package com.abu.auth.controller;

import cn.hutool.core.util.StrUtil;
import com.abu.auth.service.AuthService;
import com.abu.auth.utils.JwtUtils;
import com.abu.common.Resp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

@RestController
@RequestMapping("auth")
public class SimpleAuthController {

    @Autowired
    private AuthService authService;

    @PostMapping("login")
    public Resp userAuth(@RequestParam("cardNum") String cardNum, @RequestParam("password") String password) {
//        获取token
        String token = this.authService.userAuth(cardNum, password);
        if (StrUtil.isNotEmpty(token)) {
            return Resp.ok().data("userToken", token);
        }
        return Resp.error().msg("授权失败");
    }

    @GetMapping("userInfo")
    public Resp queryUserInfo(HttpServletRequest request) {
        HashMap<String,Object> paramData = this.authService.getUsernameAndImgAndUserId(request);
        return Resp.ok().data(paramData);
    }

}
